<template>
	<div class="components-container">
        <!-- 新增/修改 -->
        <sweet-modal ref="dialog" class="dialog">
          <h3>{{title}}</h3>
            <div style=" height:200px; margin:30px 50px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">所属区域</label>
                        <div class="layui-input-inline" style="width:455px;">
                           <el-select v-model="ashesData.ASSASAID" placeholder="请选择区域" style="width:100%">
                            <el-option v-for="item in areaTypes" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                          </el-select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                      <label class="layui-form-label">位置编号</label>
                      <div class="layui-input-inline" style="width:455px;">
                        <el-input  v-model="ashesData.ASSNO" placeholder="请输入位置编号"></el-input>
                      </div>
                </div>
                </div>
                 <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">横坐标</label>
                        <div class="layui-input-inline">
                            <el-input-number v-model="ashesData.ASSXP" :min="1" :max="xMax"></el-input-number>
                        </div>
                        <label class="layui-form-label">纵坐标</label>
                        <div class="layui-input-inline">
                            <el-input-number v-model="ashesData.ASSYP" :min="1" :max="yMax"></el-input-number>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="closeDialog">取消</el-button>
                <el-button type="primary" @click="submit" :loading="this.$store.state.isloading">确定</el-button>
            </div>
        </sweet-modal>
        <!-- 详情 -->
        <sweet-modal ref="dialogInfo" class="dialog">
          <h3>{{title}}</h3>
            <div style=" height:200px; margin:30px 50px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">所属区域</label>
                        <div class="layui-input-inline" style="width:465px;">
                           <el-input  v-model="ashesData.ASSNAME" placeholder="请输入位置编号" readonly></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                      <label class="layui-form-label">位置编号</label>
                      <div class="layui-input-inline" style="width:465px;">
                        <el-input  v-model="ashesData.ASSNO" placeholder="请输入位置编号" readonly></el-input>
                      </div>
                </div>
                </div>
                 <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">横坐标</label>
                        <div class="layui-input-inline">
                          <el-input  v-model="ashesData.ASSXP" placeholder="请输入位置编号" readonly></el-input>
                        </div>
                        <label class="layui-form-label">纵坐标</label>
                        <div class="layui-input-inline">
                          <el-input  v-model="ashesData.ASSYP" placeholder="请输入位置编号" readonly></el-input>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="closeDialog">取消</el-button>
            </div>
        </sweet-modal>
	</div>

</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
</style>
<script>
import sweetModal from "@/components/sweetModal";
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";

const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";

export default {
  name: "ashesManage",
  props: {
    orderType: {
      type: String,
      default() {
        return ADD;
      }
    }
  },
  data() {
    return {
      title: null,
      ashesData: {},

      xMax: 100,
      yMax: 100,

      ashesTypes: [],
      areaTypes: []
    };
  },
  watch: {
    "ashesData.ASSASAID": function(val) {
      if (
        this.ashesData.ASSASAID !== null &&
        this.ashesData.ASSASAID !== undefined &&
        this.ashesData.ASSASAID !== ""
      ) {
        var data = {
          ASAID: this.ashesData.ASSASAID
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Ashesarea.Detail,
          res => {
            this.xMax = res.data.content.ASAXCOUNT;
            this.yMax = res.data.content.ASAYCOUNT;
          },
          res => {
            this.$message.error(res.data.msg);
          }
        );
      }
    }
  },
  methods: {
    //获取位置类别
    getAssType() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Ashes.QueryAshesArea,
        res => {
          let assTypeData = res.data.content.OutData,
            legendsUsersData = assTypeData.map(item => ({
              label: item.ASANAME,
              value: item.ASAID
            }));
          this.areaTypes = legendsUsersData;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //功能操作
    open(order,id) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case ADD:
          this.title = "位置新增";
          this.initSelectData();
          this.$refs.dialog.open();
          break;
        case MODIFY:
          this.title = "位置修改";
          this.initSelectData();
          this.dataInfo(id);
          this.$refs.dialog.open();
          break;
        case DELETE:
          this.dataDelete(id);
          break;
        case INFO:
          this.title = "位置详情";
          this.dataInfo(id);
          this.$refs.dialogInfo.open();
          break;
        default:
      }
    },
    //提交
    submit() {
      this.$store.state.isloading = true;
      switch (this.order) {
        case ADD:
          this.dataAdd();
          break;
        case MODIFY:
          this.dataModify();
          break;
        case DELETE:
          break;
        case INFO:
          this.$refs.dialogInfo.close();
          break;
        default:
      }
    },
    //取消
    cancel() {
      this.$refs.dialog.close();
      this.$refs.dialogInfo.close();
    },
    //位置新增
    dataAdd() {
      let data = JSON.parse(JSON.stringify(this.ashesData));
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Ashes.Create,
        res => {
          this.refreshData();
          this.$refs.dialog.close();
          this.$message({
            message: this.order + res.data.msg,
            type: "success"
          });
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //位置修改
    dataModify() {
      let data = JSON.parse(JSON.stringify(this.ashesData));
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Ashes.Modify,
        res => {
          this.refreshData();
          this.$refs.dialog.close();
          this.$message({
            message: this.order + res.data.msg,
            type: "success"
          });
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //位置删除
    dataDelete(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(callback => {
        var data = {
          ASSID: id
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Ashes.Delete,
          res => {
            this.refreshData();
            this.$message({
              message: this.order + res.data.msg,
              type: "success"
            });
          },
          res => {
            this.$message.error(res.data.msg);
          }
        );
      });
    },
    //位置详情
    dataInfo(id) {
      var data = {
        ASSID: id
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Ashes.Detail,
        res => {
          this.ashesData = res.data.content;
          this.ashesData.ASSID = id;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //数据重置
    dataRepeat() {
      this.ashesData = {};
    },
    //初始化下拉框数据
    initSelectData() {
      this.getAssType();
    },
    refreshData() {
      this.$emit("refreshData");
    },
    closeDialog() {
      if (this.order === ADD || this.order === MODIFY)
        this.$refs.dialog.close();
      else if (this.order === INFO) this.$refs.dialogInfo.close();
    }
  },
  components: {
    sweetModal
  },
  mounted() {},
  created() {}
};
</script>